import { hasOwn } from "../shared/index"

const publicPropertiesMap = {
    $el:(i) => i.vnode.el,
    $slots:(i) => i.slots,
    $props:(i) => i.props
}

// 通过proxy代理，使访问this时 可以直接返回目标的属性值
export const PublicInstanceProxyHandlers = {
    get({_:instance},key) {
        const { setupState,props } = instance
        // if(key in setupState) {
        //     console.log('instance',instance);
        //     return setupState[key]
        // }
        // if(key in props) {
        //     return props[key]
        // }
        if(hasOwn(setupState,key)) {
            return setupState[key]
        } else if(hasOwn(props,key)) {
            return props[key]
        }

        const publicGetter = publicPropertiesMap[key]
        if(publicGetter) {
            return publicGetter(instance)
        }
    }
}